package com.tensai.teach.luogu;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author Tensai
 */
public class P1003 {
    static int[][] map;
    static int x = 0, y = 0;

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int[][] data = new int[n][4];
        int i = 0;
        while (i < n) {
            Scanner cin2 = new Scanner(System.in);
            data[i][0] = cin2.nextInt();
            data[i][1] = cin2.nextInt();
            data[i][2] = cin2.nextInt();
            data[i][3] = cin2.nextInt();
            x = Math.max(x, data[i][0] + data[i][2]);
            y = Math.max(y, data[i][1] + data[i][3]);
            i++;
        }
        initMap();
        for (int j = 0; j < n; j++) {
            for (int x = 0; x < data[j][2]; x++) {
                for (int y = 0; y < data[j][3]; y++) {
                    map[data[j][0] + x][data[j][1] + y] = j + 1;
                }
            }
        }

        Scanner cin3 = new Scanner(System.in);
        int p = cin3.nextInt();
        int q = cin3.nextInt();
        if (p >= x || q >= y) {
            System.out.println(-1);
        } else {
            System.out.println(map[p][q]);
        }
    }

    private static void initMap() {
        map = new int[x][y];
    }
}
